const $ = jQuery = (function(window) {
  let jquery = function(nodeSelector) {
    this.nodes = document.querySelectorAll(nodeSelector)
  }

  jquery.prototype = {
    each: function(callback) {
      for (let i = 0; i < this.nodes.length; i++) {
        callback.call(this, i, this.nodes[i])
      }
    },
    // 添加class方法
    addClass: function(classes) {
      let className = classes.split(' ')
      className.forEach(value => {
        // 循环class
        this.each(function(index, obj) {
          obj.classList.add(value)
        })
      });
    },
    // 修改text
    setText: function(text) {
      this.each(function(index, obj) {
        obj.textContent = text
      })
    }
  }

  return function(nodeSelector) {
    return new jquery(nodeSelector)
  }

})()